<?php
	$root = $_SERVER['DOCUMENT_ROOT'];
	include($root . "/util/session.php");//checks that the user is logged in
	include($root . "/util/privilege_check.php");
	checkPrivilege("student");
	if (isset($_POST['chapterID'])) {
		$actualSubject = $_POST['subjectID'];
		$actualChapter = $_POST['chapterID'];
		$username = mysqli_real_escape_string($db,$_SESSION['login_user']);
		$query = "SELECT * FROM results_info WHERE subjectID='$actualSubject' and chapterID = '$actualChapter' and studentUser = '$username'";
		$result = mysqli_query($db,$query);
		$i = 1;
	}else{
		echo 'Error in reviewResults - No POST reached';
	}
?>

<html>
	<head>
		<title>Review exam</title>
		<link rel="stylesheet" type="text/css" href="studentStyle.css">
		<style>
			#results_info {
			  	font-family: Arial, Helvetica, sans-serif;
			 	border-collapse: collapse;
			  	width: 100%;
			  	font-size: 24px;
			}

			#results_info td, #results_info th {
	  			border: 1px solid #ddd;
	  			padding: 8px;
	  			text-align: center;
	  			background-color: white;
			}

			#results_info th {
				padding-top: 12px;
				padding-bottom: 12px;
				text-align: center;
				background-color: #4CAF50;
				color: white;
			}
		</style>
	</head>
	<body>
		<?php
				include($root . "/student/header.php")
		?>
		<li><a href="/student/checkResults.php">Back</a></li>

		<table border="1px" id="results_info">
			<thead>
				<tr>
					<th>Question number</th>
					<th>Question type</th>
					<th>Question description</th>
					<th>Answer A</th>
					<th>Answer B</th>
					<th>Answer C</th>
					<th>Answer D</th>
					<th>Your answer</th>
					<th>Correct answer</th>
					<th>Points obtained</th>
				</tr>
			</thead>
			<tbody>
				<?php
					while($row=mysqli_fetch_assoc($result)){
						$questionID = $row['questionID'];
						$query2 = "SELECT * FROM questions WHERE questionID = '$questionID'";
						$result2 = mysqli_query($db,$query2);
						$row2 = mysqli_fetch_assoc($result2);?>
						<tr>
							<td><?php echo $i; ?></td>
							<td><?php echo $row2['questionType'];?></td>
							<td><?php echo $row2['questionDescription'];?></td>
							<td><?php echo $row2['descriptionAnswerA'];?></td>
							<td><?php echo $row2['descriptionAnswerB'];?></td>
							<td><?php echo $row2['descriptionAnswerC'];?></td>
							<td><?php echo $row2['descriptionAnswerD'];?></td>
							<td><?php echo $row['studentAnswer'];?></td>
							<td><?php echo $row['correctAnswer'];?></td>
							<?php if($row['studentAnswer'] == $row['correctAnswer']){?>
								<td><?php echo $row2['correctPoints'];?></td>
							<?php }else{?>
								<td><?php echo '-'. $row2['assHolePoints'];?></td>
							<?php }?>
						</tr>
			  <?php $i = $i+1;}?>
			</tbody>
		</table>


		<?php
				include($root . "/student/footer.php")
		?>
	</body>
</html>
